package com.qf.contract.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.exception.ControllerException;
import com.qf.common.base.exception.ServiceException;
import com.qf.common.base.result.RespResult;
import com.qf.common.base.result.ResultCode;
import com.qf.contract.qo.ContractInformationQueryQo;
import com.qf.contract.service.ContractInformationQueryService;
import com.qf.contract.vo.ContractInformationQueryVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "全部合同状态查询")
@RestController
@RequestMapping("/contractinformationquery")
public class ContractInformationQueryController {
    @Resource
    ContractInformationQueryService contractInformationQueryService;

    @ApiOperation("全部合同状态查询")
    @GetMapping("/contractinformationquerylist")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "页码"),
            @ApiImplicitParam(name = "size", value = "页数")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult contractInformationQuerylist(ContractInformationQueryQo contractInformationQueryQo, @RequestParam(defaultValue = "1") int current, @RequestParam(defaultValue = "10") int size) {
        try {
            IPage<ContractInformationQueryVo> contractApprovalVoIPage = contractInformationQueryService.contractInformationQuery(contractInformationQueryQo, current, size);
            System.out.println(contractApprovalVoIPage);
            return RespResult.success(contractApprovalVoIPage);
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("基本信息查询")
    @GetMapping("/basicinformationquery")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "合同id", required = true),

    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult basicInformationQuery(int id) {
        try {
            return RespResult.success(contractInformationQueryService.basicInformationQuery(id));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("签订单位查询")
    @GetMapping("/signingunitquery")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "合同id", required = true),

    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult signingUnitQuery(int id) {
        try {
            return RespResult.success(contractInformationQueryService.signingUnitQuery(id));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("合同明细查询")
    @GetMapping("/contractdetailsquery")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "合同id", required = true),

    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult contractDetailsQuery(int id) {
        try {
            return RespResult.success(contractInformationQueryService.contractDetailsQuery(id));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("合同变更信息查询")
    @GetMapping("/changeinformation")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "合同id", required = true),

    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult changeInformation(int id) {
        try {
            return RespResult.success(contractInformationQueryService.changeInformation(id));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }


}
